package tutorial.api.new_api.front_page;


import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import public_util.model.PublicAgentInfo;
import public_util.model.ReturnData;
import public_util.servlet.ServletParent;
import public_util.tool_4_handle.Tool_4_Servlet;
import system_api_4_trade.dao.ApiPublicAgentInfoMapper;
import tutorial.basic_sql.DBOperation;
import tutorial.basic_sql.Tutorial4MiddleMapper;
import tutorial.basic_sql.Tutorial4MiddleTable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;

/**
 * 工具类放这里方便复制
 */
public class Tutorial4FrontPageTool {

    private static Logger logger = Logger.getLogger(Tutorial4FrontPageTool.class);

    /**
     * 推荐在具体方法里面, 完成SQL的open和close
     */
    public static ReturnData showDemo(SqlSessionFactory sqlSession, ServletParent thisParent, HttpServletResponse response, HttpServletRequest request){
        logger.info("----showDemo----");
        SqlSession session = sqlSession.openSession();
        ApiPublicAgentInfoMapper agentInfoMapper = session.getMapper(ApiPublicAgentInfoMapper.class);
        Tutorial4FrontPageMapper ampleMapper = session.getMapper(Tutorial4FrontPageMapper.class);
        Tutorial4MiddleMapper tMiddleMaper = session.getMapper(Tutorial4MiddleMapper.class);

        ReturnData data = new ReturnData();
        HashMap<String, Object> mapData = new HashMap<String, Object>();
        PublicAgentInfo centerAgentInfo = null;
        try{
            //获取到界面的基本信息
            String username =  request.getParameter("username");
            String password =  request.getParameter("password");
            logger.info("user_name:" + username);
            HashMap<String, Object> para = new HashMap<>();
            logger.info("user_name:" + ampleMapper.showTableList(para));

            Tutorial4MiddleTable.batch_insert_contact_table(session, tMiddleMaper, 20);
            session.commit();
        }
        catch(Exception e)
        {
            String msg = Tool_4_Servlet.showStackTrace(e);
            data.setMsg(msg);
        }
        finally
        {
            session.close();
        }
        logger.info("Landing success");
        return data;
    }
}